package web.servlet;

import domain.Account;
import domain.Order;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

public class ConfirmOrderServlet extends HttpServlet {

    private static final String CONFIRM_ORDER_FORM = "/WEB-INF/jsp/order/confirmOrder.jsp";

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        HttpSession session = req.getSession();
        Account loginAccount = (Account) session.getAttribute("loginAccount");
        Order order=(Order)session.getAttribute("order");
        order.setCardType(req.getParameter("order.cardType"));
        order.setCreditcard(req.getParameter("order.creditcard"));
        order.setExprdate(req.getParameter("order.expiryDate"));

        boolean ship= Boolean.parseBoolean(req.getParameter("Ship"));
        if(ship){
            order.setShipToFirstName(req.getParameter("shippingFirstName"));
            order.setShipToLastName(req.getParameter("shippingLastName"));
            order.setShipAddress1(req.getParameter("shippingAddress1"));
            order.setShipAddress2(req.getParameter("shippingAddress2"));
            order.setShipCity(req.getParameter("shippingCity"));
            order.setShipState(req.getParameter("shippingState"));
            order.setShipZip(req.getParameter("shippingZip"));
            order.setShipCountry(req.getParameter("shippingCountry"));
        }

        session.setAttribute("order",order);
        session.setAttribute("isShip",ship);
        req.getRequestDispatcher(CONFIRM_ORDER_FORM).forward(req, resp);
    }
}
